<?php
session_start();
/*
 * Session variables:
 * $_SESSION['type'] [string] = user type of the logged in user
 * $_SESSION['authorised'] [boolean] = whether or not the current user is logged in
 * $_SESSION['student_pass'] [string]= password of student who arrived
 */
if(isset($_SESSION['authorised']) && $_SESSION['authorised'] == true)
{   
    if(isset($_SESSION['type']))
    {
        if($_SESSION['type'] == 'administrator')
        {
			$tutor_paymentmode=strtoupper(addslashes(pg_escape_string($_POST['tutor_paymentmode'])));
			$amount_tutor=strtoupper(addslashes(pg_escape_string($_POST['amount_tutor'])));
			$teacher_id = $_SESSION['teacher_id'];
			
        	if($amount_tutor=='')
            {
            	$_SESSION['error']='Error in managing the payment system. Put information in all fields.';
				header('Location:admin_alert.php');
                exit();
            }
			
			include('connection.inc');
            
            $sql = "Update teachers set mode='$tutor_paymentmode', per_mode='$amount_tutor' where teacher_id='$teacher_id'";
            $result = pg_query($sql);
            header('Location:admin_managepaymentmode.php');
            exit();
        }
        elseif($_SESSION['type'] == 'student')
        {
            header('Location: student_index.php');
            exit();
        }
        elseif($_SESSION['type'] == 'tutor')
        {
            header('Location: tutor_index.php');
            exit();
        }
        elseif($_SESSION['type'] == 'parent')
        {
            header('Location: parent_index.php');
            exit();
        }
    }
}
else
{
    header('Location: index.php');
}
?>
